from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage


def paginator(obj, page, per=10):
    """
    自定义通用分页器
    :param obj: 对象
    :param page: 页数
    :param per: 每页个数
    :return:
    """
    objPage = Paginator(obj, per)
    try:
        objList = objPage.page(page)
    except PageNotAnInteger:
        objList = objPage.page(1)
    except EmptyPage:
        objList = objPage.page(1)
    return objList
